package com.chixing.day10.day10_Homew;

import java.util.Arrays;

public class Company{
      private int compID;
      private String compName;
      private String compType;
      private String comFlag;
      private int count;
      private Job[] jobs = new Job[5];

    public Company() {
    }

    public Company(int compID, String compName, String compType, String comFlag) {
        this.compID = compID;
        this.compName = compName;
        this.compType = compType;
        this.comFlag = comFlag;
    }

    public Job[] getJobs(){
        return jobs;
    }

    public int getCompID() {
        return compID;
    }

    public void setCompID(int compID) {
        this.compID = compID;
    }

    public String getCompName() {
        return compName;
    }

    public void setCompName(String compName) {
        this.compName = compName;
    }

    public String getCompType() {
        return compType;
    }

    public void setCompType(String compType) {
        this.compType = compType;
    }

    public String getComFlag() {
        return comFlag;
    }

    public void setComFlag(String comFlag) {
        this.comFlag = comFlag;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    @Override
    public String toString() {
        return "Company{" +
                "compID=" + compID +
                ", compName='" + compName + '\'' +
                ", compType='" + compType + '\'' +
                ", comFlag='" + comFlag + '\'' +
                ", count=" + count +
                ", jobs=" + Arrays.toString(jobs) +
                '}';
    }

    public Job[] sendJob() throws OutBoundException{
        if(this.getCount() >= 5){
            throw new OutBoundException();
        }else{
            Job job  = new Job();
            for(int i = 0; i < count; i++){
                if(jobs[0] == null){
                    jobs[0] = job;
                    this.setCount(this.getCount() + 1);
                    return jobs;
                }else if(jobs[i].equals(job)){
                    return jobs;
                }
                jobs[this.count] = job;
                this.setCount(this.getCount() + 1);
            }
            return jobs;
        }
    }
}